package com.caesar.Prime;

/**
 * @author caesar
 * @date 2025/7/19
 * @Description:
 * @apiNote
 */
public class FindPrime {
    public static boolean isPrime(int num) {
        if (num <= 1) return false;
        if (num == 2) return true;
        if (num % 2 == 0) return false;
        for (int i = 3; i <= Math.sqrt(num); i += 2) {
            if (num % i == 0) return false;
        }
        return true;
    }
    public static void findMersennePrimes() {
        int n = 1;
        while (true) {
            int mersenne = (1 << n) - 1; // 计算 2^n - 1
            if (mersenne >= 1000) break;
            if (isPrime(mersenne)) {
                System.out.println("符合条件的数: " + mersenne + " (2^" + n + " - 1)");
            }
            n++;
        }
    }
    public static void main(String[] args) {
        long start = System.currentTimeMillis();

        findMersennePrimes();

        long end = System.currentTimeMillis();
        System.out.println("耗时：" + (end - start) + " 毫秒");
    }
}
